package org.examples.controller;

import org.examples.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class TestController {

    @GetMapping("/hello")
    public ResponseEntity<String> hello(){
        return ResponseEntity.ok("hello,sentinel") ;
    }

    //线程直接失败
    @GetMapping("/thread")
    public ResponseEntity<String> threadMode() throws InterruptedException {
        TimeUnit.SECONDS.sleep(1);
        return ResponseEntity.ok("hello,sentinel!") ;
    }

    @GetMapping("/test1")
    public ResponseEntity<String> test1(){
        return ResponseEntity.ok("hello,test1") ;
    }

    @GetMapping("/test2")
    public ResponseEntity<String> test2(){
        return ResponseEntity.ok("hello,test2") ;
    }

    @Autowired
    private TestService testService ;

    @GetMapping("/link1")
    public ResponseEntity<String> link1(){
        return ResponseEntity.ok( String.format("link1,调用 test,结果为%s",testService.hello())) ;
    }

    @GetMapping("/link2")
    public ResponseEntity<String> lin2(){
        return ResponseEntity.ok(String.format("link2,调用 test,结果为%s",testService.hello())) ;
    }
}
